package com.easyfun.healthmagicbox.comm.json;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.DoctorAndHospital;
import com.easyfun.healthmagicbox.pojo.DoctorProfile;

public class DoctorAndHospitalJsonWrapper {
	DoctorAndHospital mpp;
	public DoctorAndHospitalJsonWrapper(DoctorAndHospital pp)
	{
		mpp = pp;
	}
    public DoctorAndHospitalJsonWrapper(JSONObject obj) throws JSONException {
        deserializeFromObj(obj);
    }
 
    public DoctorAndHospitalJsonWrapper(String serializedObj) throws JSONException {
        deserialize(serializedObj);
    }
 
    public void deserialize(String serializedObj) throws JSONException {
        JSONObject obj = new JSONObject(serializedObj);
        deserializeFromObj(obj);
    }
 
    public void deserializeFromObj(JSONObject obj) throws JSONException {
    	
    	mpp.setHospitalID(obj.getString("HospitalID"));
    	mpp.setHospitalName(obj.getString("HospitalName"));
    }
 
    public String serialize() throws JSONException {
        return serializeToObj().toString();
    }
 
    public JSONObject serializeToObj() throws JSONException {
        JSONObject serializedObj = new JSONObject();
        serializedObj.put("HospitalID", mpp.getHospitalID());
        serializedObj.put("HospitalName", mpp.getHospitalName());
 
        return serializedObj;
    }
    
    public static ArrayList<DoctorAndHospitalJsonWrapper> deserializeArray(String serializedArray) throws JSONException {
        JSONArray jsonObjs = new JSONArray(serializedArray);
        ArrayList<DoctorAndHospitalJsonWrapper> pps = new ArrayList<DoctorAndHospitalJsonWrapper>();
        for (int i=0; i<jsonObjs.length(); i++) {
            JSONObject pp = jsonObjs.getJSONObject(i);
            pps.add(new DoctorAndHospitalJsonWrapper(pp));
        }
 
        return pps;
    }
}
